<template>
	<view class="bg-white">
		<view class="flex padding" v-for="(item,index) in cartList" :key="index">
			<view class="flex align-center">
				<text 
					class="iconfont icon-gouxuan margin-right"
					:class="item.ischeck?'text-yellow':'text-grey'"
					@click="handleCheck(index)"
				></text>
				<image class="poster margin-right" :src="item.img" mode=""></image>
			</view>
			<view class="flex justify-between info list">
				<view class="">
					{{item.name}}
					<view class="margin-tb-xs">{{item.french}}</view>
					￥{{item.list[item.dropIdx].price}}
				</view>
				<view class="flex flex-direction align-end">
					<view @click="handleEdit(item,index)" class="edit margin-bottom-xs">
						<text class="iconfont icon-bianji"></text>
					</view>
					{{item.list[item.dropIdx].spec}}
					 X 
					{{item.num}}
				</view>
			</view>
		</view>
		<view class="my-fixed cu-bar foot bg-fff flex">
			<view class="flex flex-sub padding align-center">
				<text 
					class="iconfont icon-gouxuan margin-right-xs"
					:class="allInfo.allCheck?'text-yellow':'text-grey'"
					@click="handleAllCheck(allInfo.allCheck)"
				></text>全选
				<view class="margin-left">
					共计:{{allInfo.checkPrice}}
				</view>
			</view>
			<view @click="handleOrder" class="bg-yellow padding text-center color-fff">
				立即结算
			</view>
		</view>
		<cart-modal/>
	</view>
</template>

<script>
	import {mapState,mapMutations,mapGetters} from 'vuex'
	export default {
		computed: {
			...mapState({
				cartList:state=>state.cart.cartList,
				modalShow:state=>state.cart.modalShow,
				userInfo:state=>state.user.userInfo
			}),
			...mapGetters({
				allInfo:'cart/allInfo'
			})
		},
		watch:{
			cartList(){
				console.log('检测到了购物车变化');
				uni.setStorage({
					key:'cartList',
					data:this.cartList
				})
			}
		},
		onShow() {
			if(!this.userInfo){
				uni.showModal({
					title:'温馨提示',
					content:'您需要先登录才能进行您的操作',
					confirmText:'立即登录',
					confirmColor:'brown',
					cancelText:'稍后再说',
					success: ({confirm}) => {
						if(confirm){
							uni.navigateTo({
								url:'/pages/login/login'
							})
						}else{
							uni.switchTab({
								url:'/pages/home/home'
							})
						}
					}
				})
			}
		},
		methods: {
			handleEdit(goodObj,editIdx) {
				this.$store.commit('cart/modalMut',true)
				this.$store.commit('cart/modalDataMut',{
					goodObj,editIdx
				})
			},
			handleOrder(){
				if(this.allInfo.checkPrice==0){
					uni.showToast({
						title:'请勾选商品后结算',
						icon:'none'
					})
					return
				}
				uni.navigateTo({
					url:'/pages/order/order'
				})
			},
			...mapMutations({
				handleCheck:'cart/cartCheckMut',
				handleAllCheck:'cart/cartAllCheckMut'
			})
		},
	}
</script>

<style lang="scss">
page{
	padding-bottom: 100upx;
}
.poster{
	width: 180upx;
	height: 180upx;
	background-color: #d8d8d8;
}
.info{
	&.list{
		width: 60%;
	}
	.edit{
		width: 80upx;
		height: 80upx;
		text-align: center;
		line-height: 80upx;
		background-color: #e6e6e6;
		border-radius: 50%;
		
	}
}
.flex.align-end{
	min-width: 210upx;
}
// .icon-gouxuan{
// 	color: #e7e7e7;
// }
.cu-btn.lg{
	width: 50%;
}
.cover-cont{
	position: absolute;
	top: 50%;
	left: 0;
	width: 690upx;
	transform: translateY(-50%);
	border-radius: 10upx;
}
.drop{
	position: relative;
	.drop-list{
		width: 300upx;
		position: absolute;
		top: 60upx;
		right: 0;
		box-shadow: 0 0 10upx 2upx rgba(0,0,0,0.2);
		z-index: 10;
		view:hover{
			background-color: #e6e6e6;
		}
	}
}
.my-fixed{
	bottom: 100upx;
}
</style>
